#array.py
#Create arrays for tenure,cohort,namespace # of edits plot

#Input path and cohort, outputs arrays in sys.out

import sys
import collections


def main():
	colorList = ["red","orange","goldenrod4","black","green","coral","violet","skyblue"]
	maximum = 0
	tenureDict = collections.defaultdict(list)
	path = sys.argv[1]
	year = sys.argv[2]
	f = open(path,"r")
	namespace = path.split('/')[-1].replace(".txt","")
	for line in f:
		tokens = line.split(' ')
		if tokens[0] == "Stats":
			continue
		if year in tokens[0]:
			tenureDict[tokens[0][5:6]].append(int(tokens[1].replace('\n','')))
	for y in sorted(tenureDict.keys()):	
		maximum = max(maximum,max(tenureDict[y]))
		aList = []
		for item in tenureDict[y]:
			aList.append(str(item))
		
		print "tenure"+ y + " <- c(" + ",".join(aList) + ')'
	print 'jpeg("'+namespace+" "+year+'.jpeg")'
	print 'plot(tenure' + str(len(tenureDict.keys())-1) + ', type="o", main="Namespace: ' + namespace + ", Start Year: " + year + '",xlab="Number of years",ylab="Number of edits",col="blue",ylim=c(0,'+ str(maximum) +'))'
	for x in range(0,len(tenureDict.keys())-1):
		print "lines(tenure"+str(x)+',type="o",col="'+colorList[x]+'")'
	print "dev.off()"


main()
